local yulin = fk.CreateSkill{
  name = "wk_heg__yulin",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["wk_heg__yulin"] = "鱼鳞",
  [":wk_heg__yulin"] = "<a href='heg_formation_skill'>阵法技</a>，若你是围攻角色，此围攻关系中的围攻角色使用【杀】对被围攻角色造成伤害后，此围攻角色回复1点体力。<br />"..
    "<font color = 'gray'>注：阵法技来源于紫星居设计-文聘，已取得紫乔授权。",
  ["@@wk_heg__yulin"] = "鱼鳞",
}

local H = require "packages/ol_hegemony/util"


yulin:addEffect("arraysummon", {
  array_type = "siege",
})

yulin:addEffect(fk.Damage,{
  can_trigger = function(self, event, target, player, data)
    return player:hasShownSkill(yulin.name) and data.card and data.card.trueName == "slash" 
      and H.inSiegeRelation(target, player, data.to) and #player.room.alive_players > 3
  end,
  on_use = function(self, event, target, player, data)
    player.room:recover({
      who = target,
      num = 1,
      recoverBy = player,
      skillName = yulin.name,
    })
  end,
})

--阵法标记
local yulin_spec = {
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local ret = #room.alive_players > 3 and player:hasSkill(yulin.name)
    local prev = player:getLastAlive()
    local next = player:getNextAlive()
    local clear = true
      if ret and H.inSiegeRelation(prev:getLastAlive(), player, prev) then
        room:setPlayerMark(prev:getLastAlive(), "@@wk_heg__yulin", 1)
        room:setPlayerMark(player, "@@wk_heg__yulin", 1)
        clear = false
      end
      if ret and H.inSiegeRelation(player, next:getNextAlive(), next) then
        room:setPlayerMark(player, "@@wk_heg__yulin", 1)
        room:setPlayerMark(next:getNextAlive(), "@@wk_heg__yulin", 1)
        clear = false
      end
      if clear == true then
        for _, p in ipairs(room.alive_players) do
          room:setPlayerMark(p, "@@wk_heg__yulin", 0)
        end
      end
  end,
}

yulin:addEffect(fk.GeneralHidden,{
  can_refresh = function(self, event, target, player, data)
      return  player == target and not player:hasShownSkill(yulin.name)
  end,
  on_refresh = function(self, event, target, player, data)
      local room = player.room
      for _, p in ipairs(room.alive_players) do
        room:setPlayerMark(p, "@@wk_heg__yulin", 0)
    end
  end,
})

--失去技能
yulin:addLoseEffect(function (self, player, is_death)
  for _, p in ipairs(player.room.alive_players) do
    if p:getMark("@@wk_heg__yulin") > 0 then
      player.room:setPlayerMark(p, "@@wk_heg__yulin", 0)
    end
  end
end)

yulin:addEffect(fk.TurnStart,{
  can_refresh = function(self, event, target, player, data)
    return player:hasShownSkill(yulin.name,true,true)
  end,
  on_refresh =yulin_spec.on_refresh,
})

yulin:addEffect(fk.GeneralRevealed,{
  can_refresh = function(self, event, target, player, data)
      return player:hasShownSkill(yulin.name,true,true)
  end,
  on_refresh = yulin_spec.on_refresh,
})

yulin:addEffect(fk.EventAcquireSkill,{
  can_refresh = function(self, event, target, player, data)
      return player:hasShownSkill(yulin.name,true,true)
  end,
  on_refresh = yulin_spec.on_refresh,
})

--队列发生改变
yulin:addEffect(H.PlayerRemoved,{
  can_refresh = function(self, event, target, player, data)
      return player:hasShownSkill(yulin.name,true,true)
  end,
  on_refresh = yulin_spec.on_refresh,
})

yulin:addEffect(H.GeneralRemoved,{
  can_refresh = function(self, event, target, player, data)
    return player:hasShownSkill(yulin.name,true,true)
  end,
on_refresh = yulin_spec.on_refresh,
})

yulin:addEffect(fk.Death,{
  can_refresh = function(self, event, target, player, data)
      return player:hasShownSkill(yulin.name,true,true)
  end,
  on_refresh = yulin_spec.on_refresh,
})


return yulin